home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Anagaal / Source / Includes / NGLIterator.hh next >
Encoding:
Text File  |  2000-06-24  |  879 b   |  53 lines

  1. /*    ==============
  2.  *    NGLIterator.hh
  3.  *    ==============
  4.  *    
  5.  *    Copyright 2000 Joshua Juran
  6.  */
  7.  
  8. #pragma once
  9.  
  10. #include "NGLList.hh"
  11.  
  12. template <class Type>
  13. class NGLIterator {
  14. public:
  15.     NGLIterator(NGLList<Type> &inList);
  16.     virtual ~NGLIterator();
  17.     
  18.     virtual bool GetNext(Type &outDatum);
  19.     
  20. protected:
  21.     NGLList<Type> &mList;
  22.     NGLListNode<Type> *mCurrentNode;
  23. };
  24.  
  25. template <class Type>
  26. NGLIterator<Type>::NGLIterator(NGLList<Type> &inList)
  27. : mList(inList)
  28. {
  29.     mCurrentNode = mList.BeginIteration();
  30. }
  31.  
  32. template <class Type>
  33. NGLIterator<Type>::~NGLIterator()
  34. {
  35.     mList.EndIteration();
  36. }
  37.  
  38. template <class Type>
  39. bool
  40. NGLIterator<Type>::GetNext(Type &outDatum)
  41. {
  42.     while (mCurrentNode && mCurrentNode->WasDeleted()) {
  43.         mCurrentNode = mCurrentNode->Next();
  44.     }
  45.     if (mCurrentNode) {
  46.         outDatum = mCurrentNode->Datum();
  47.         mCurrentNode = mCurrentNode->Next();
  48.         return true;
  49.     }
  50.     return false;
  51. }
  52.  
  53.